﻿<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="basePath" value="${pageContext.request.contextPath}"/>
<script>var BASE_PATH = '${basePath}';</script>
<!-- 全局js -->
<script src="${basePath}/resources/hplus/js/jquery.min.js?v=2.1.4"></script>
<script src="${basePath}/resources/hplus/js/bootstrap.min.js?v=3.3.6"></script>

<!-- 自定义js -->
<script src="${basePath}/resources/hplus/js/content.js?v=1.0.0"></script>


<!-- Bootstrap table -->
<script src="${basePath}/resources/hplus/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
<script src="${basePath}/resources/hplus/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
<script src="${basePath}/resources/hplus/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<script src="${basePath}/resources/wen/js/dictselect.js"></script>
<script src="${basePath}/resources/wen/js/layer/layer.js"></script>
<script src="${basePath}/resources/zheng-admin/plugins/jquery-confirm/jquery-confirm.min.js"></script>
<script src="${basePath}/resources/zheng-admin/js/aeye_ztree.js"></script>
<script src="${basePath}/resources/zheng-admin/plugins/waves-0.7.5/waves.min.js"></script>
<script src="${basePath}/resources/hplus/js/plugins/validate/jquery.validate.min.js"></script>
<script src="${basePath}/resources/zheng-admin/plugins/select2/js/select2.min.js"></script>
<script src="${basePath}/resources/zheng-admin/plugins/zTree_v3/js/jquery.ztree.all.min.js"></script>
<script>
$(function() {
	$.ajaxSetup( {
        //设置ajax请求结束后的执行动作
        complete :
        function(XMLHttpRequest, textStatus) {
            // 通过XMLHttpRequest取得响应头，sessionstatus
            var sessionstatus = XMLHttpRequest.getResponseHeader("SECURITYSTATUS");
            if (sessionstatus == "NOT") {
                var win = window;
                while (win != win.top){
                    win = win.top;
                }
                win.location.href= XMLHttpRequest.getResponseHeader("CONTEXTPATH");
            }
        }
    });
});
// 动态高度
function getHeight() {
	return $(window).height() - 20;
}

var defalutBootstrapTableParams = {
            height: getHeight(),
            striped: true,
            search: true,
            showRefresh: true,
            showColumns: true,
            minimumCountColumns: 2,
            clickToSelect: true,
            pagination: true,
            paginationLoop: false,
            sidePagination: 'server',
            singleSelect:true,
            silentSort: false,
            smartDisplay: false,
            escape: true,
            searchOnEnterKey: true,
            idField: 'id',
            maintainSelected: true,
            toolbar: '#toolbar',
            formatLoadingMessage: function () {
                return "请稍等，正在加载中...";
              },
            formatNoMatches: function () {
                return '无符合条件的记录';
            }
}

var $table;
function aeye_table($table,params){
    params['onLoadError'] = function (data) {
                              $table.bootstrapTable('removeAll');
                          };
    var object = $.extend({}, defalutBootstrapTableParams, params);
    $table.bootstrapTable(object);
}

$.fn.serializeJsonObject = function () {
    var json = {};
    var form = this.serializeArray();
    $.each(form, function () {
        if (json[this.name]) {
            if (!json[this.name].push) {
                json[this.name] = [json[this.name]];
            }
            json[this.name].push();
        } else {
            json[this.name] = this.value || '';
        }
    });
    return json;
}

/**
 * 全屏打开
 * @param title
 * @param url
 * @returns
 */
function aeye_open(title,url,area){
    if(!area){
        area = ['100%','100%'];
    }
	var index = layer.open({
		area:area,
		type: 2,
		title: title,
		content: url
	});
}

function aeye_open_div(title,url,area){
    if(!area){
        area = ['70%','90%'];
    }
	var index = layer.open({
		area:area,
		type: 1,
		title: title,
		content: url
	});
	return index;
}
/**
 * 关闭子窗口本身
 * @returns
 */
function aeye_close(){
	var index = parent.layer.getFrameIndex(window.name);
	parent.layer.close(index);
}

function aeye_confirm(params,action){
	var defualtConfirmParams = {
		title: false,
		backgroundDismiss:true,
		buttons: {
			cancel: {
				text: '确认',
				btnClass: 'waves-effect waves-button waves-light'
			}
		}
	}
	if(action){
		defualtConfirmParams = {
			type: 'red',
 			animationSpeed: 300,
 			title: false,
 			content: '确认执行此操作吗？',
 			buttons: {
 				confirm: {
 					text: '确认',
 					btnClass: 'waves-effect waves-button',
 					action: action
 				},
 				cancel: {
 					text: '取消',
 					btnClass: 'waves-effect waves-button'
 				}
 			}
		}
	}
	if(params!=null && params!=undefined && params!=''){
		if(typeof(params)=='string'){
			defualtConfirmParams['content'] = params;
		}else{
			for(var key in params){
				defualtConfirmParams[key] = params[key];
			}
		}
	}
	debugger;
	return $.confirm(defualtConfirmParams);
}
/**
 * ajax提交
 * @param url
 * @param data
 * @param callBack
 * @returns
 */
function aeye_ajax(url,data,callBack){
	var layerLoad;
    $.ajax({
        type: 'post',
        url: url,
        data: data,
        beforeSend: function() {
			layerLoad = layer.load(2);
        },
		complete:function(){
			layer.close(layerLoad);
		},
        success: function(result) {
			if (result.code != 1) {
				if (result.data instanceof Array) {
					$.each(result.data, function(index, value) {
						aeye_confirm({content:value.data});
					});
				} else {
					aeye_confirm({content:result.data});
				}
			} else {
				if(callBack){
					callBack(result);
				}
			}
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
        	aeye_confirm({content:textStatus});
        }
    });
}
/**
 * ajax提交，成功后重新加载父页面数据，并关闭子页面本身
 * @param url
 * @param data
 * @param callBack
 * @returns
 */
function aeye_ajaxSubmit(url,data,callBack){
	aeye_ajax(url,data,function(result){
		if(parent.$table){
			parent.$table.bootstrapTable('refresh');
		}
		aeye_close();
		if(callBack){
			callBack(result);
		}
	});
}

function aeye_deleteSingle(url,params,message,callBack){
	if(!message){
		message = '确认删除吗？';
	}
	var deleteDialog = aeye_confirm(message,function(){
		aeye_ajax(url,params,function(result){
			deleteDialog.close();
			$table.bootstrapTable('refresh');
			if(callBack){
				callBack(result);
			}
		});
	});
}

function aeye_deleteMulti(url,pkfield,message,callBack){
	var rows = $table.bootstrapTable('getSelections');
	if (!rows || rows.length == 0) {
		aeye_confirm({content: '请至少选择一条记录！',autoClose: 'cancel|3000'});
	}else{
		if(!message){
			message = '确认删除此('+rows.length+')条记录吗？';
		}
		var deleteDialog = aeye_confirm(message,function(){
			var ids = new Array();
			for (var i in rows) {
				ids.push(rows[i][pkfield]);
			}
			if(!(url.substr(url.length-1)=='/' || url.substr(url.length-1)=='\\')){
				url += '/';
			}
			url += ids.join("-");

			aeye_ajax(url,null,function(result){
				deleteDialog.close();
				$table.bootstrapTable('refresh');
				if(callBack){
					callBack(result);
				}
			});
		});
	}
}
</script>